babl/babl-component.c babl/babl-conversion.c babl/babl-db.c
authorSven Neumann <sven@gimp.org>
Sat, 29 Mar 2008 19:02:20 +0000 (19:02 +0000)
committerSven Neumann <neo@src.gnome.org>
Sat, 29 Mar 2008 19:02:20 +0000 (19:02 +0000)
2008-03-29  Sven Neumann  <sven@gimp.org>

* babl/babl-component.c
* babl/babl-conversion.c
* babl/babl-db.c
* babl/babl-extension.c
* babl/babl-fish-path.c
* babl/babl-fish-reference.c
* babl/babl-fish-simple.c
* babl/babl-format.c
* babl/babl-model.c
* babl/babl-type.c: applied patch from Jan Heller that changes
the
code to test for a pre-existent instance of a babl class in the
database before creating a new one.

svn path=/trunk/; revision=298

ChangeLog
babl/babl-component.c
babl/babl-conversion.c
babl/babl-db.c
babl/babl-extension.c
babl/babl-fish-path.c
babl/babl-fish-reference.c
babl/babl-fish-simple.c
babl/babl-format.c
babl/babl-model.c
babl/babl-type.c

index ec56ead736edd8b2ea43e2971c03b8324d426a55..5193253c781bd9196fa2728da61386c730f4df24 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2008-03-29  Sven Neumann  <sven@gimp.org>
+
+       * babl/babl-component.c
+       * babl/babl-conversion.c
+       * babl/babl-db.c
+       * babl/babl-extension.c
+       * babl/babl-fish-path.c
+       * babl/babl-fish-reference.c
+       * babl/babl-fish-simple.c
+       * babl/babl-format.c
+       * babl/babl-model.c
+       * babl/babl-type.c: applied patch from Jan Heller that changes the
+       code to test for a pre-existent instance of a babl class in the
+       database before creating a new one.
+
 2008-03-24  Tor Lillqvist  <tml@novell.com>
 
        * babl/babl-type.c: Make the "test" array static.
index 84562cc175c2b55033ae27676105ebc48e5c7b9b..ef28dc69b95008b707494160d63d7c1a52c60ab4 100644 (file)
@@ -109,14 +109,22 @@ babl_component_new (void *first_arg,
 
   va_end (varg);
 
+  babl = babl_db_exist (db, id, first_arg);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl = component_new (first_arg, id, luma, chroma, alpha);
 
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  return babl;
 }
 
 BABL_CLASS_TEMPLATE (component)
index 27eb77e750dc99c7afc38c0bebd95202e4c3ff89..ab122bb9da927447fcb8ad6c4a3e2c92e590e499 100644 (file)
@@ -79,7 +79,7 @@ conversion_new (const char    *name,
           }
         else if (planar)
           {
-            babl_fatal ("planar conversions not supported for %ssupported",
+            babl_fatal ("planar conversions not supported for %s",
                         babl_class_name (source->class_type));
           }
         break;
@@ -257,18 +257,26 @@ babl_conversion_new (void *first_arg,
     {
       type = BABL_CONVERSION_PLANAR;
     }
-  babl = conversion_new (create_name (source, destination, type),
-                         id, source, destination, linear, plane, planar);
-
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    else
-      babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl);
-
-    return ret;
-  }
+
+  char * name = create_name (source, destination, type);
+  
+  babl = babl_db_exist (db, id, name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
+  babl = conversion_new (name, id, source, destination, linear, plane, planar);
+
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl);
+  return babl;
 }
 
 static long
index 735bdbc3da6527d8af32b807303deb25a25edafa..2cd95a7f126676d5768f7a7650d68e71b689e92e 100644 (file)
@@ -94,12 +94,6 @@ Babl *
 babl_db_insert (BablDb *db,
                 Babl   *item)
 {
-
-  Babl *found = babl_db_exist (db, item->instance.id, item->instance.name);
-
-  if (found)
-    return found;
-
   if (item->instance.id)
     babl_hash_table_insert (db->id_hash, item);
   babl_hash_table_insert (db->name_hash, item);
index ebadb5f5dc93feda6d5d8c60fc1fcea4133f6806..9219fadeb64f3f2723b2977f8bd0c3bb581a25e7 100644 (file)
@@ -184,7 +184,7 @@ babl_extension_load (const char *path)
   init = dlsym (dl_handle, "init");
   if (!init)
     {
-      babl_log ("\n\tint babl_extension_init() function not found in extenstion '%s'", path);
+      babl_log ("\n\tint babl_extension_init() function not found in extension '%s'", path);
       dlclose (dl_handle);
       return load_failed (babl);
     }
@@ -202,7 +202,8 @@ babl_extension_load (const char *path)
       return load_failed (babl);
     }
 
-  if (babl_db_insert (db, babl) == babl)
+  babl_db_insert (db, babl);
+  if (babl == babl_db_exist_by_name (db, path))
     {
       babl_set_extender (NULL);
       return babl;
index afbb1df02a3089b5b7759161192a5d797fc666c1..ada4116f283cd1b808c57311231c63d92120017f 100644 (file)
@@ -284,6 +284,15 @@ babl_fish_path (const Babl *source,
   char           *name = create_name (source, destination, 1);
   BablConversion *temp_chain[BABL_HARD_MAX_PATH_LENGTH];
 
+  babl = babl_db_exist_by_name (babl_fish_db (), name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl_assert (BABL_IS_BABL (source));
   babl_assert (BABL_IS_BABL (destination));
 
@@ -329,12 +338,11 @@ babl_fish_path (const Babl *source,
       return NULL;
     }
 
-  {
-    Babl *ret = babl_db_insert (babl_fish_db (), babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * name, inserting newly created class into database.
+   */
+  babl_db_insert (babl_fish_db (), babl);
+  return babl;
 }
 
 static long
index 073f7dbda61ecbdeefc04889a2fa7886a77994a9..beb5364c155cf5a749def68faed5944ee42a4b78 100644 (file)
@@ -51,6 +51,15 @@ babl_fish_reference (const Babl *source,
   Babl *babl = NULL;
   char *name = create_name (source, destination, 1);
 
+  babl = babl_db_exist_by_name (babl_fish_db (), name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl_assert (BABL_IS_BABL (source));
   babl_assert (BABL_IS_BABL (destination));
 
@@ -71,12 +80,12 @@ babl_fish_reference (const Babl *source,
   babl->fish.error       = 0.0;  /* assuming the provided reference conversions for types
                                     and models are as exact as possible
                                   */
-  {
-    Babl *ret = babl_db_insert (babl_fish_db (), babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+
+  /* Since there is not an already registered instance by the required
+   * name, inserting newly created class into database.
+   */
+  babl_db_insert (babl_fish_db (), babl);
+  return babl;
 }
 
 
index 0d096a2861474fc5b4d8db7016613293e56b1383..6c933d858c9eb3a9885556dfac1f16ed53055f79 100644 (file)
@@ -34,6 +34,15 @@ babl_fish_simple (BablConversion *conversion)
 
   name = create_name (conversion);
 
+  babl = babl_db_exist_by_name (babl_fish_db (), name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl = babl_malloc (sizeof (BablFishSimple) +
                       strlen (name) + 1);
   babl->class_type    = BABL_FISH_SIMPLE;
@@ -50,10 +59,9 @@ babl_fish_simple (BablConversion *conversion)
                                    reference, and babl fish reference only requests clean
                                    conversions */
 
-  {
-    Babl *ret = babl_db_insert (babl_fish_db (), babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * name, inserting newly created class into database.
+   */
+  babl_db_insert (babl_fish_db (), babl);
+  return babl;
 }
index ab4fc60a2343e4a47f2258ddf6913b1381fa723f..0a166699a0cb0c7ff36b0d30b5d4c3388a16623f 100644 (file)
@@ -45,24 +45,25 @@ format_new (const char     *name,
 {
   Babl *babl;
 
-  {
-    int i;
-    /* i is desintation position */
-    for (i = 0; i < model->components; i++)
-      {
-        int j;
-
-        for (j = 0; j < components; j++)
-          {
-            if (component[j] == model->component[i])
-              goto component_found;
-          }
-        babl_fatal ("matching source component for %s in model %s not found",
-                    model->component[i]->instance.name, model->instance.name);
-component_found:
-        ;
-      }
-  }
+  /* i is desintation position */
+  int i, j, component_found = 0;
+  for (i = 0; i < model->components; i++)
+    {
+      for (j = 0; j < components; j++)
+        {
+          if (component[j] == model->component[i])
+            {
+              component_found = 1;
+              break;
+            }  
+        }
+      if (!component_found) 
+        {
+          component_found = 0;
+          babl_fatal ("matching source component for %s in model %s not found",
+                      model->component[i]->instance.name, model->instance.name);
+        }
+    }
 
   /* allocate all memory in one chunk */
   babl = babl_malloc (sizeof (BablFormat) +
@@ -295,17 +296,28 @@ babl_format_new (void *first_arg,
 
   va_end (varg);
 
-  babl = format_new (name ? name : create_name (model, components, component, type),
+  if (!name) 
+    name = create_name (model, components, component, type);
+
+  babl = babl_db_exist (db, id, name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+    
+  babl = format_new (name,
                      id,
                      planar, components, model,
                      component, sampling, type);
 
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  return babl;
 }
 
 int
index 99ef35e36ee00b60eb211a473ff66fa31a9ebc32..6a212b5fb19d935f966884251b5d231be9bf7110 100644 (file)
@@ -161,14 +161,24 @@ babl_model_new (void *first_argument,
 
   va_end (varg);
 
-  babl = model_new (create_name (name, components, component), id, components, component);
+  name = create_name (name, components, component);
 
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  babl = babl_db_exist (db, id, name);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
+  babl = model_new (name, id, components, component);
+
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  return babl;
 }
 
 
index 7004dd64c681635c1e7c39b6933f3f01a728faec..3a182e2457270676f5cdc472d3ff5213f0b17ffd 100644 (file)
@@ -128,14 +128,22 @@ babl_type_new (void *first_arg,
 
   va_end (varg);
 
+  babl = babl_db_exist (db, id, first_arg);
+  if (babl) 
+    {
+      /* There is an instance already registered by the required id/name,
+       * returning the preexistent one instead.
+       */
+      return babl;
+    }
+
   babl = type_new (first_arg, id, bits);
 
-  {
-    Babl *ret = babl_db_insert (db, babl);
-    if (ret != babl)
-      babl_free (babl);
-    return ret;
-  }
+  /* Since there is not an already registered instance by the required
+   * id/name, inserting newly created class into database.
+   */
+  babl_db_insert (db, babl);
+  return babl;
 }